package com.itheima.shop.fly_weight_review;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: design
 * @description:
 * @author: zhanghz001
 * @create: 2021-02-27 14:45
 **/
@Component
public class AuthorizationInterceptorReview implements HandlerInterceptor {
    @Autowired
    SessionThreadLocalReview sessionThreadLocalReview;
    
    @Override
    public boolean preHandle(HttpServletRequest request
            , HttpServletResponse response
            , Object handler) throws Exception {
        String username = request.getParameter("username");
        SessionShareReview value = new SessionShareReview();
        value.setUsername(username);
        sessionThreadLocalReview.set(value);
        return true;
    }
    
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
                           Object handler, ModelAndView modelAndView) throws Exception {
    }
    
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response
            , Object handler, Exception ex) throws Exception {
        System.out.println(sessionThreadLocalReview.get());
        sessionThreadLocalReview.remove();
    }
}
